class ConfigInfo {
    constructor(db) {
      this.db = db;
    }
  
    async createTable() {
      const sql = `
        CREATE TABLE IF NOT EXISTS config_info (
          name TEXT PRIMARY KEY,
          value TEXT,
          remark TEXT
        );
      `;
      await this.db.query(sql);
      console.log('ConfigInfo table created.');
    }
  
    async insert(name, value, remark) {
      const sql = 'INSERT INTO config_info (name, value, remark) VALUES (?, ?, ?)';
      const configId = await this.db.insert(sql, [name, value, remark]);
      return configId;
    }
  
    async getByName(name) {
      const sql = 'SELECT * FROM config_info WHERE name = ?';
      const configs = await this.db.query(sql, [name]);
      return configs[0];
    }
  
    async getAll() {
      const sql = 'SELECT * FROM config_info';
      return await this.db.query(sql);
    }
  
    async update(name, value, remark) {
      const sql = 'UPDATE config_info SET value = ?, remark = ? WHERE name = ?';
      const changes = await this.db.update(sql, [value, remark, name]);
      return changes;
    }
  
    async delete(name) {
      const sql = 'DELETE FROM config_info WHERE name = ?';
      const changes = await this.db.delete(sql, [name]);
      return changes;
    }
  }
    
  module.exports = ConfigInfo;